package yesjava.news.web;

import yesjava.news.entity.News;
import yesjava.news.service.NewsService;
import yesjava.news.service.NewsServiceImpl;
import yesjava.news.utils.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list-news.do")
public class ListNewsServlet extends HttpServlet {
    NewsService newsService = new NewsServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageNo = request.getParameter("pageNo");
        pageNo = (pageNo==null?"1":pageNo.trim());
        String pageSize = request.getParameter("pageSize");
        pageSize = (pageSize==null?"10":pageSize.trim());

        Page<News> page = newsService.findAll(Integer.parseInt(pageNo),Integer.parseInt(pageSize));
        request.setAttribute("page",page);
        request.getRequestDispatcher("/WEB-INF/page/news-list.jsp").forward(request,response);
    }
}
